<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/5/17 0017
 * Time: 17:33
 */
namespace App\Admin\Models;
use App\Base\Models\BaseModel;

/**
 * 配置分类表
 * Class ConfigClassModel
 * @package App\Admin\Models
 */
class  ConfigClassModel extends BaseModel
{
    /**
     * 表名
     * @var string
     */
    public $table = "config_class";
    /**
     * 开启时间
     * @var bool
     */
    public $timestamps = true;
    /**
     * The name of the "created at" column.
     *
     * @var string
     */
    const CREATED_AT = 'create_time';  //修改添加时间字段
    /**
     * The name of the "updated at" column.
     *
     * @var string
     */
    const UPDATED_AT = 'update_time';
    /**
     * 模型的日期字段保存格式。
     */
    protected $dateFormat = 'U';
    /**
     * 分类别名
     * @var array
     */
    protected $appends = ['pname'];

    public function getPnameAttribute(){
        $pid=$this->pid;
        $pname=$this->newQuery()->where("id",$pid)->pluck("name");
        $prturn=!empty($pname->toArray())?$pname:'顶级节点';
        return $prturn;
    }

}